package com.guava;

import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.UnmodifiableIterator;
import com.google.common.io.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

/**
 * 描述:
 *
 * @author luzhongfu
 * Created by lucky on 2021-10-09 9:41 AM
 */
public class FileTest {

    public static void main(String[] args) throws Exception{
        File file = new File("/Users/luzhongfu/Downloads/user_upload.sql");
//        CharSource charSource = Files.asCharSource(file, Charsets.UTF_8);
//        ImmutableList<String> strings = charSource.readLines();
//
//        UnmodifiableIterator<String> iterator = strings.iterator();
//
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//        }

        //读
        ByteSource byteSource = Files.asByteSource(file);
        byte[] read = byteSource.read();
//        System.out.println(new String(read));

        File file1 = new File("/Users/luzhongfu/Downloads/user_upload2.sql");
//        OutputStream outputStream = new FileOutputStream(file1);

//        byteSource.copyTo(outputStream);

        //写
        ByteSink byteSink = Files.asByteSink(file1, FileWriteMode.APPEND);
        byteSink.write(read);


    }
}
